<template>
    <div>
        <div @click="goback"><i class="iconfont icon-fanhui"></i></div>
        <div class="header">
            <span>订单详情</span>
        </div>
        <div class="view">
            <div class="content-tips" v-if="false">目前暂无课程订单</div>
            <div class="content">
                <div class="top">
                    <div>订单号：{{allview.order_no}}</div>
                    <div>已支付</div>
                    <div class="clear"></div>
                </div>
                <div class="msg">
                    <div>
                        <img :src="allview.course.teacher_img"/>
                    </div>
                    <div>
                        <span>{{allview.course.title}}</span>
                        <span class="clear"></span>
                    </div>
                    <span class="clear"></span>
                </div>
                <div class="bottom">
                    <div>时间：{{allview.group.start_time}}&nbsp;&nbsp;&nbsp;</div>
                    <div>地点：{{allview.group.region}}</div>
                    <div class="b-btn" v-show="allview.status === '成团'">支付尾款</div>
                    <div class="clear" style="margin-bottom: 10px"></div>
                </div>
                <!--<div class="bottom">-->
                    <!--<div>总计：<span style="color: #f0341d;">￥599</span>&nbsp;&nbsp;</div>-->
                    <!--<div style="margin-bottom: 10px">-->
                        <!--订金：<span style="color: #f0341d;">￥299</span>&nbsp;&nbsp;-->
                        <!--尾款：<span style="color: #f0341d;">￥299</span>-->
                    <!--</div>-->
                    <!--<div class="clear"></div>-->
                <!--</div>-->
                <div class="order-content" style="padding: 0 10px 6px 10px">
                    <div>
                        <div style="float: left">课程订金：</div>
                        <div style="float: right;">￥{{allview.fee_order}}</div>
                        <div class="clear"></div>
                    </div>
                    <div>
                        <div style="float: left">课程尾款：</div>
                        <div style="float: right;">￥{{allview.fee_tail === -1 ? '待定' : allview.fee_tail}}</div>
                        <div class="clear"></div>
                    </div>
                    <div>
                        <div style="float: left;">已付款：</div>
                        <div style="float: right;color: #f0341d; ">￥{{allview.status !== '已支付' ? allview.fee_order : allview.fee_tail + allview.fee_order}}</div>
                        <div class="clear"></div>
                    </div>
                </div>
                <div class="line"></div>
                <div class="order">
                    <div class="order-tips">定金信息</div>
                    <div class="order-content">
                        <div>
                            <div style="float: left">付款时间：</div>
                            <div style="float: right">{{allview.order.pay_time}}</div>
                            <div class="clear"></div>
                        </div>
                        <div>
                            <div style="float: left">支付方式：</div>
                            <div style="float: right">微信支付</div>
                            <div class="clear"></div>
                        </div>
                        <div>
                            <div style="float: left">支付状态：</div>
                            <div style="float: right">{{allview.order.pay_status}}</div>
                            <div class="clear"></div>
                        </div>
                    </div>
                </div>
                <div class="line"></div>
                <div class="order">
                    <div class="order-tips">尾款信息</div>
                    <div class="order-content">
                        <div>
                            <div style="float: left">付款时间：</div>
                            <div style="float: right">{{allview.tail.pay_time}}</div>
                            <div class="clear"></div>
                        </div>
                        <div>
                            <div style="float: left">支付方式：</div>
                            <div style="float: right">微信支付</div>
                            <div class="clear"></div>
                        </div>
                        <div>
                            <div style="float: left">支付状态：</div>
                            <div style="float: right">{{allview.tail.pay_status}}</div>
                            <div class="clear"></div>
                        </div>
                    </div>
                </div>
            </div>
          <!--支付-->
          <div class="main-kefu" v-show="isKefu">
            <div class="main-more">
              <p class="title">
                <span>请选择支付方式</span><br/>
                <span>人数过半即众筹成功，余款在封团后3天内支付。 若不成功，预订金原路足额返还。</span>
                <span class="iconfont icon-untitled94" @click="aloseSel"></span>
              </p>
              <p class="mimg"><img src="../../assets/school/puyweixin.png" alt=""><span class="iconfont icon-gou"></span></p>
              <p class="mbtn" @click="addPay(allview.id)">确认支付￥{{allview.fee_tail}}</p>
            </div>
          </div>
        </div>
    </div>
</template>

<script>
import msgbox from '@/common/msgbox.js'
import { Toast } from 'mint-ui'
export default {
  name: 'orderview',
  data () {
    return {
      isKefu: false,
      allview: {
        course: {},
        order: {},
        tail: {},
        group: {}
      }
    }
  },
  mounted () {
    this.getView()
  },
  methods: {
    aloseSel () {
      this.isKefu = false
    },
    addPay (val) {
      let that = this
      this.$g.ajax({
        path: 'courseordersubs/pay/' + val,
        methods: 'post',
        cbSuccess (res) {
          /* eslint-disable no-undef */
          WeixinJSBridge.invoke(
            'getBrandWCPayRequest', {
              'appId': 'wx4999af4af069bec3',
              'timeStamp': res.memo.timeStamp,
              'nonceStr': res.memo.nonceStr,
              'package': res.memo.package,
              'signType': res.memo.signType,
              'paySign': res.memo.paySign
            },
            function (wxres) {
              if (wxres.err_msg === 'get_brand_wcpay_request:ok') {
                that.$router.push('/paidsucc/' + that.allview.fee_tail)
              } else if (wxres.err_msg === 'get_brand_wcpay_request:cancel') {
                Toast({
                  message: '已取消支付',
                  position: 'bottom',
                  duration: 1500
                })
              } else {
                Toast({
                  message: '支付失败',
                  position: 'bottom',
                  duration: 1500
                })
              }
            }
          )
        },
        cbError (data) {
          let msg = msgbox.get(data.msg)
          Toast({
            message: msg,
            position: 'bottom',
            duration: 1000
          })
        }
      })
    },
    goback () {
      this.$router.go(-1)
    },
    getView () {
      let that = this
      this.$g.ajax({
        path: 'courseorders/view/' + this.$route.params.id,
        method: 'post',
        cbSuccess: function (data) {
          that.allview = data.memo
          if (that.allview.order.pay_status === 'nopay') {
            that.allview.order.pay_status = '未支付'
          }
          if (that.allview.order.pay_status === 'part') {
            that.allview.order.pay_status = '部分退款'
          }
          if (that.allview.order.pay_status === 'paid') {
            that.allview.order.pay_status = '已支付'
          }
          if (that.allview.order.pay_status === 'refund') {
            that.allview.order.pay_status = '退款 '
          }
          if (that.allview.tail.pay_status === 'nopay') {
            that.allview.tail.pay_status = '未支付'
          }
          if (that.allview.tail.pay_status === 'part') {
            that.allview.tail.pay_status = '部分退款'
          }
          if (that.allview.tail.pay_status === 'paid') {
            that.allview.tail.pay_status = '已支付'
          }
          if (that.allview.tail.pay_status === 'refund') {
            that.allview.tail.pay_status = '退款 '
          }
          if (that.allview.status === 'nopay') {
            that.allview.status = '未支付'
          }
          if (that.allview.status === 'paid') {
            that.allview.status = '已支付'
          }
          if (that.allview.status === 'cancel') {
            that.allview.status = '取消'
          }
          if (that.allview.status === 'completed') {
            that.allview.status = '完成'
          }
          if (that.allview.status === 'create') {
            that.allview.status = '成团'
          }
          if (that.allview.status === 'order') {
            that.allview.status = '定金'
          }
        },
        cbError: function (data) {
          let msg = msgbox.get(data.msg)
          Toast({
            message: msg,
            position: 'bottom',
            duration: 1000
          })
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
  .main-kefu{
    width: 100%;
    height: 100%;
    background: rgba(178,178,178,0.6);
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 999;
    text-align: center;
    .main-more{
      width: 100%;
      background: white;
      min-height: 100px;
      position: absolute;
      bottom: 0px;
      .mbtn{
        width: 94%;
        line-height: 40px;
        border-radius: 5px;
        float: left;
        margin-left: 3%;
        margin-bottom: 10px;
        color: white;
        background: #0033a0;
        font-size: 13px;
        margin-top: 20px;
      }
      .title{
        margin-top: 15px;
        position: relative;
        padding: 0 3%;
        span:nth-of-type(1){
          font-weight: 700;
          font-size: 16px;
        }
        span:nth-of-type(2){
          font-size: 12px;
          color: #666;
        }
        span:nth-of-type(3){
          position: absolute;
          right: 3%;
          top: 0;
          color: #666;
          font-size: 14px;
        }
      }
      .mimg{
        margin-top: 10px;
        img{
          float: left;
          margin-left: 3%;
        }
        span{
          float: right;
          margin-right: 3%;
          color: #0033a0;
          line-height: 30px;
          font-size: 20px;
        }
      }
    }
    i{
      font-size: 40px;
      color: white;
      line-height: 60px;
    }
  }
    .line{
        height: 12px;
        background-color: #f2f2f2;
    }
    .icon-fanhui{
        position: absolute;
        color: #ffffff;
        top: 12px;
        left: 10px;
    }
    .header{
        background-color: #0640a1;
        color: #ffffff;
        padding: 10px 0;
        text-align: center;
    }
    .content-tips {
        text-align: center;
        font-size: 12px;
        color: #e5e5e5;
        margin: 10px 0;
        padding: 20px 0;
        background-color: #ffffff;
    }
    .view{
        position: relative;
        top: -10px;
    }
    .content{
        margin: 10px 0;
        background-color: #ffffff;
        .top{
            font-size: 14px;
            padding: 10px 10px;
            border-bottom: 1px solid #e5e5e5;
            div:nth-of-type(1){
                float: left;
                color: #999999;
                position: relative;
                top: 2px;
            }
            div:nth-of-type(2){
                float: right;
                color: #0640a1;
            }
        }
        .msg{
            background-color: #fafafa;
            padding: 10px 10px;
            div{
                float: left;
            }
            div:nth-of-type(1){
                width: 28%;
                height: 70px;
            }
            div:nth-of-type(2){
                margin-left: 6px;
                width: 70%;
                height: 70px;
                font-size: 16px;
                span:nth-of-type(1){
                    display: block;
                    min-height: 44px;
                    line-height: 24px;
                    margin: 4px 0 4px 0;
                }
            }
            img{
                width: 100%;
                height: 100%;
            }
        }
        .bottom{
            padding: 10px 10px;
            font-size: 14px;
            border-bottom: 1px solid #e5e5e5;
            div:nth-of-type(1){
                float: left;
                position: relative;
                top: 5px;
            }
            div:nth-of-type(2){
                float: left;
                position: relative;
                top: 5px
            }
          .b-btn{
            background-color: #0640a1;
            color: #ffffff;
            float: right;
            position: relative;
            top: 5px;
            padding: 3px 8px;
            border: 1px solid #0640a1;
            border-radius: 5px;
          }
        }
        .order{
            padding: 10px;
            .order-tips{
                border-left: 2px solid #0640a1;
                padding-left: 4px;
                color: #383838;
            }
        }
        .order-content{
            margin-top: 10px;
            font-size: 14px;
            line-height: 30px;
            color: #5b5b5b;
            padding: 0 6px;
        }
    }
</style>
